Using OLR
vclust <- varclus (~angle+brick+wood+mixed+ density+EN +TC + TC_mature_soil + TC_saprolite_soil + TC_weath_rock + TC_unstable_structure + T_construction + spring + landfill + garbage + crack + leaning_wall + scars + downward_floor + tilted + fracture + conc_rainfall + wastewater + leak + septic_tank + tree + ground_veg + deforestation + banana + drainage , data=train.data)
# took out density since training has 0 d4 and it was not allowing do the plot
p <- plot(vclust)
par(mfrow=c(6,5))
plot.xmean.ordinaly (risk~angle+brick+wood+mixed+ density+EN +TC + TC_mature_soil + TC_saprolite_soil + TC_weath_rock + TC_unstable_structure + T_construction + spring + landfill + garbage + crack + leaning_wall + scars + downward_floor + tilted + fracture + conc_rainfall + wastewater + leak + septic_tank + tree + ground_veg + deforestation + banana + drainage, data=train.data, cr=TRUE , subn=FALSE)
#angle + building+density+EN +TC + TC_mature_Soil + TC_saprolito + TC_weath_rock + TC_rock + TC_geol_desfav + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + DepTaludeAterro + aterro + lixo + entulho + crack + belly_wall + scars + drawback + tilted + fracture + conc_rainfall_water + wastewater + leak + septic_tank + drainage + tree + ground_veg + deforestation + banana
Diagnostic 2: Proportion (-5% of one of the parameters based on what is expected. Since some parameters have 2 predictors, others 5)
#library(plyr)
brick <- count(train.data$brick) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "brick")
wood <- count(train.data$wood) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "wood")
mixed <- count(train.data$mixed) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "mixed")
TC_mature_soil <- count(train.data$TC_mature_soil) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "TC_mature_soil")
T_construction <- count(train.data$T_construction ) %>%
mutate ("Percentage"=(freq/265)*100) %>%
mutate("Classifier" = "T_construction ")
spring <- count(train.data$spring) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "spring")
landfill <- count(train.data$landfill) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "landfill")
garbage <- count(train.data$garbage) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "garbage")
crack <- count(train.data$crack) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "crack")
leaning_wall <- count(train.data$leaning_wall) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "leaning_wall")
scars <- count(train.data$scars) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "DepTaludeAterro")
downward_floor <- count(train.data$downward_floor) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "scars")
tilted <- count(train.data$tilted) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "tilted")
conc_rainfall <- count(train.data$conc_rainfall) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "conc_rainfall")
wastewater <- count(train.data$wastewater) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "wastewater")
leak <- count(train.data$leak) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "conc_rainfall_water")
septic_tank <- count(train.data$septic_tank) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "septic_tank")
angle <- count(train.data$angle) # angle A less than 5% but the rest are okay (3,50, 91, 277, 109) Expected=106
angle <- angle %>%
mutate("Percentage"=(freq/106)*100)%>%
mutate("Classifier" = "angle")
EN <- count(train.data$EN) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "EN")
TC <- count(train.data$TC) %>%
mutate ("Percentage"=(freq/265)*100) %>%
mutate("Classifier" = "TC")
TC_saprolite_soil <- count(train.data$TC_saprolite_soil ) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "TC_saprolite_soil ")
banana <- count(train.data$banana) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "banana")
drainage <- count(train.data$drainage) %>%
mutate ("Percentage"=(freq/176.7)*100)%>%
mutate("Classifier" = "drainage")
deforestation <- count(train.data$deforestation) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "deforestation")
TC_unstable_structure <- count(train.data$TC_unstable_structure ) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "TC_unstable_structure ")
tree <- count(train.data$tree) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "tree")
ground_veg <- count(train.data$ground_veg) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "ground_veg")
density <- count(train.data$density) %>% #(79, 415, 36) # d4 =0
mutate ("Percentage"=(freq/132.5)*100)%>%
mutate("Classifier" = "density")
TC_weath_rock <- count(train.data$TC_weath_rock ) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "TC_weath_rock ")
fracture <- count(train.data$fracture) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "fracture")
df <- rbind(brick, wood, mixed, TC_mature_soil, T_construction, spring, landfill, garbage, crack, leaning_wall, scars, downward_floor, tilted, conc_rainfall, wastewater, leak, septic_tank, angle, EN, TC, TC_saprolite_soil, banana, drainage, deforestation, TC_unstable_structure, tree, ground_veg,density, TC_weath_rock, fracture)
df
## x freq Percentage Classifier
## 1 FALSE 32 12.0754717 brick
## 2 TRUE 498 187.9245283 brick
## 3 FALSE 454 171.3207547 wood
## 4 TRUE 76 28.6792453 wood
## 5 FALSE 491 185.2830189 mixed
## 6 TRUE 39 14.7169811 mixed
## 7 FALSE 251 94.7169811 TC_mature_soil
## 8 TRUE 279 105.2830189 TC_mature_soil
## 9 FALSE 213 80.3773585 T_construction
## 10 TRUE 317 119.6226415 T_construction
## 11 FALSE 510 192.4528302 spring
## 12 TRUE 20 7.5471698 spring
## 13 FALSE 326 123.0188679 landfill
## 14 TRUE 204 76.9811321 landfill
## 15 FALSE 347 130.9433962 garbage
## 16 TRUE 183 69.0566038 garbage
## 17 FALSE 445 167.9245283 crack
## 18 TRUE 85 32.0754717 crack
## 19 FALSE 500 188.6792453 leaning_wall
## 20 TRUE 30 11.3207547 leaning_wall
## 21 FALSE 321 121.1320755 DepTaludeAterro
## 22 TRUE 209 78.8679245 DepTaludeAterro
## 23 FALSE 468 176.6037736 scars
## 24 TRUE 62 23.3962264 scars
## 25 FALSE 426 160.7547170 tilted
## 26 TRUE 104 39.2452830 tilted
## 27 FALSE 14 5.2830189 conc_rainfall
## 28 TRUE 516 194.7169811 conc_rainfall
## 29 FALSE 206 77.7358491 wastewater
## 30 TRUE 324 122.2641509 wastewater
## 31 FALSE 337 127.1698113 conc_rainfall_water
## 32 TRUE 193 72.8301887 conc_rainfall_water
## 33 FALSE 525 198.1132075 septic_tank
## 34 TRUE 5 1.8867925 septic_tank
## 35 C 32 30.1886792 angle
## 36 D 118 111.3207547 angle
## 37 E 380 358.4905660 angle
## 38 FALSE 349 131.6981132 EN
## 39 TRUE 181 68.3018868 EN
## 40 FALSE 26 9.8113208 TC
## 41 TRUE 504 190.1886792 TC
## 42 FALSE 446 168.3018868 TC_saprolite_soil
## 43 TRUE 84 31.6981132 TC_saprolite_soil
## 44 FALSE 361 136.2264151 banana
## 45 TRUE 169 63.7735849 banana
## 46 Y 62 35.0877193 drainage
## 47 P 238 134.6915676 drainage
## 48 N 230 130.1641200 drainage
## 49 FALSE 492 185.6603774 deforestation
## 50 TRUE 38 14.3396226 deforestation
## 51 FALSE 517 195.0943396 TC_unstable_structure
## 52 TRUE 13 4.9056604 TC_unstable_structure
## 53 FALSE 215 81.1320755 tree
## 54 TRUE 315 118.8679245 tree
## 55 FALSE 147 55.4716981 ground_veg
## 56 TRUE 383 144.5283019 ground_veg
## 57 d1 69 52.0754717 density
## 58 d2 422 318.4905660 density
## 59 d3 39 29.4339623 density
## 60 FALSE 520 196.2264151 TC_weath_rock
## 61 TRUE 10 3.7735849 TC_weath_rock
## 62 FALSE 529 199.6226415 fracture
## 63 TRUE 1 0.3773585 fracture
TC_weath_rock, TC_rock_TC_geol_desf, fracture, TC_rock
f1 <- lrm(risk ~ building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + tree + ground_veg + banana , data=train.data, x=TRUE , y=TRUE)
f1 <- lrm(risk ~ building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + tree + ground_veg + banana + septic_tank +TC_mature_Soil , data=train.data, x=TRUE , y=TRUE) print (f1 , latex =TRUE , coefs =5) stargazer(anova(f1), type=“text”, style=“default”)
# Equation 1
eq_OLR_01 <- polr(risk ~ brick+ wood+ EN + TC_mature_soil + T_construction + spring+ landfill+ leak+ garbage+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ septic_tank+ conc_rainfall+ wastewater+ ground_veg + angle + TC_saprolite_soil, data= train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_01))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## brickTRUE -0.74369444 0.4575882 -1.6252483 5.205483e-02
## woodTRUE 0.93103246 0.3278246 2.8400327 2.255445e-03
## ENTRUE 0.76065809 0.3946457 1.9274453 2.696208e-02
## TC_mature_soilTRUE 0.50446573 0.2181304 2.3126795 1.037013e-02
## T_constructionTRUE 0.45604364 0.3658514 1.2465271 1.062855e-01
## springTRUE -0.32689239 0.6087008 -0.5370329 2.956224e-01
## landfillTRUE 0.11306814 0.3286765 0.3440104 3.654192e-01
## leakTRUE -0.17095573 0.2331696 -0.7331821 2.317237e-01
## garbageTRUE 0.15937798 0.2937571 0.5425502 2.937198e-01
## crackTRUE 2.07693093 0.3333863 6.2298031 2.335109e-10
## leaning_wallTRUE 1.74722530 0.5296430 3.2988734 4.853684e-04
## scarsTRUE 3.62063572 0.3319293 10.9078530 5.286192e-28
## downward_floorTRUE 1.38858260 0.3683330 3.7699112 8.165281e-05
## tiltedTRUE 1.13414341 0.3141672 3.6099997 1.530987e-04
## septic_tankTRUE 0.16805216 1.1063295 0.1519006 4.396327e-01
## conc_rainfallTRUE 1.10939042 0.5805358 1.9109769 2.800378e-02
## wastewaterTRUE 0.69843609 0.2350376 2.9715927 1.481297e-03
## ground_vegTRUE 0.88362334 0.2539747 3.4791792 2.514761e-04
## angleD 0.36800398 0.4674107 0.7873247 2.155459e-01
## angleE 0.98179588 0.5537966 1.7728457 3.812714e-02
## TC_saprolite_soilTRUE 0.06527116 0.2903751 0.2247822 4.110744e-01
## R1|R2 0.84944226 0.9201676 0.9231387 1.779675e-01
## R2|R3 4.96915322 0.9671494 5.1379376 1.388851e-07
## R3|R4 9.94969481 1.0655084 9.3379790 4.909521e-21
stargazer((ctable), type="text", style="default", digits = 2)
##
## ======================================================
## Value Std. Error t value p value
## ------------------------------------------------------
## brickTRUE -0.74 0.46 -1.63 0.05
## woodTRUE 0.93 0.33 2.84 0.002
## ENTRUE 0.76 0.39 1.93 0.03
## TC_mature_soilTRUE 0.50 0.22 2.31 0.01
## T_constructionTRUE 0.46 0.37 1.25 0.11
## springTRUE -0.33 0.61 -0.54 0.30
## landfillTRUE 0.11 0.33 0.34 0.37
## leakTRUE -0.17 0.23 -0.73 0.23
## garbageTRUE 0.16 0.29 0.54 0.29
## crackTRUE 2.08 0.33 6.23 0
## leaning_wallTRUE 1.75 0.53 3.30 0.0005
## scarsTRUE 3.62 0.33 10.91 0
## downward_floorTRUE 1.39 0.37 3.77 0.0001
## tiltedTRUE 1.13 0.31 3.61 0.0002
## septic_tankTRUE 0.17 1.11 0.15 0.44
## conc_rainfallTRUE 1.11 0.58 1.91 0.03
## wastewaterTRUE 0.70 0.24 2.97 0.001
## ground_vegTRUE 0.88 0.25 3.48 0.0003
## angleD 0.37 0.47 0.79 0.22
## angleE 0.98 0.55 1.77 0.04
## TC_saprolite_soilTRUE 0.07 0.29 0.22 0.41
## R1| R2 0.85 0.92 0.92 0.18
## R2| R3 4.97 0.97 5.14 0.0000
## R3| R4 9.95 1.07 9.34 0
## ------------------------------------------------------
less p-value = 0.10 (TC_saprolitoTRUE,TaterroTRUE, DepTaludeAterroTRUE,DepTaludeAterroTRUE,landfillTRUE, construction_depositTRUE, leakTRUE)
par(mfrow=c(5,4))
plot.xmean.ordinaly (risk~ brick+ wood+ EN + TC_mature_soil + T_construction + spring+ landfill+ leak+ garbage+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ septic_tank+ conc_rainfall+ wastewater+ ground_veg + angle + TC_saprolite_soil
,data=train.data, cr=TRUE , subn=FALSE , cex.lab=1.5, cex.axis=2, cex.sub=2, cex.main=2)
Equation 1
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ EN + TC_mature_soil + T_construction + spring+ landfill+ leak+ garbage+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ septic_tank+ conc_rainfall+ wastewater+ ground_veg + angle + TC_saprolite_soil
, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +-----------------+---+---+----+--------+------------+-----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +-----------------+---+---+----+--------+------------+-----------+
## |brick |No | 32|Inf |2.708050| 1.272965676|-0.78845736|
## | |Yes|497|Inf |2.307020|-0.076496033|-2.02405640|
## +-----------------+---+---+----+--------+------------+-----------+
## |wood |No |453|Inf |2.204605|-0.190418767|-2.25495704|
## | |Yes| 76|Inf |3.610918| 1.244324100|-0.71294981|
## +-----------------+---+---+----+--------+------------+-----------+
## |EN |No |348|Inf |1.932838|-0.492476485|-2.39789527|
## | |Yes|181|Inf |4.083171| 0.990981624|-1.29226541|
## +-----------------+---+---+----+--------+------------+-----------+
## |TC_mature_soil |No |251|Inf |1.959640|-0.248279525|-2.15800386|
## | |Yes|278|Inf |2.795756| 0.216671037|-1.72616219|
## +-----------------+---+---+----+--------+------------+-----------+
## |T_construction |No |213|Inf |1.559566|-0.867500568|-2.81839826|
## | |Yes|316|Inf |3.421000| 0.558372780|-1.53532994|
## +-----------------+---+---+----+--------+------------+-----------+
## |spring |No |509|Inf |2.285417|-0.043228735|-2.03171014|
## | |Yes| 20|Inf | Inf| 1.098612289|-0.20067070|
## +-----------------+---+---+----+--------+------------+-----------+
## |landfill |No |325|Inf |1.828127|-0.509184934|-2.52905643|
## | |Yes|204|Inf |4.615121| 0.828692673|-1.29098418|
## +-----------------+---+---+----+--------+------------+-----------+
## |leak |No |336|Inf |2.001480|-0.251314428|-2.32238772|
## | |Yes|193|Inf |3.279837| 0.431440595|-1.40583896|
## +-----------------+---+---+----+--------+------------+-----------+
## |garbage |No |347|Inf |2.066538|-0.272568435|-2.28683674|
## | |Yes|182|Inf |3.079614| 0.516690743|-1.40008768|
## +-----------------+---+---+----+--------+------------+-----------+
## |crack |No |444|Inf |2.157811|-0.345745873|-2.73724936|
## | |Yes| 85|Inf |4.430817| 2.772588722|-0.07061757|
## +-----------------+---+---+----+--------+------------+-----------+
## |leaning_wall |No |499|Inf |2.263535|-0.108322227|-2.15131488|
## | |Yes| 30|Inf | Inf| 2.639057330| 0.13353139|
## +-----------------+---+---+----+--------+------------+-----------+
## |scars |No |320|Inf |1.784487|-1.366876275|-4.36944785|
## | |Yes|209|Inf |5.337538| 2.990719732|-0.81785066|
## +-----------------+---+---+----+--------+------------+-----------+
## |downward_floor |No |467|Inf |2.190107|-0.262743124|-2.26318255|
## | |Yes| 62|Inf | Inf| 4.110873864|-0.45953233|
## +-----------------+---+---+----+--------+------------+-----------+
## |tilted |No |425|Inf |2.108895|-0.444840273|-2.50807371|
## | |Yes|104|Inf |4.634729| 2.793208009|-0.63598877|
## +-----------------+---+---+----+--------+------------+-----------+
## |septic_tank |No |524|Inf |2.317369|-0.007633625|-1.91999077|
## | |Yes| 5|Inf | Inf| 0.405465108|-1.38629436|
## +-----------------+---+---+----+--------+------------+-----------+
## |conc_rainfall |No | 14|Inf |0.000000| -Inf| -Inf|
## | |Yes|515|Inf |2.474435| 0.050496164|-1.88305089|
## +-----------------+---+---+----+--------+------------+-----------+
## |wastewater |No |206|Inf |1.693319|-0.433864583|-2.78295151|
## | |Yes|323|Inf |3.022050| 0.267843730|-1.56189697|
## +-----------------+---+---+----+--------+------------+-----------+
## |ground_veg |No |147|Inf |1.279196|-1.319602987|-2.73002911|
## | |Yes|382|Inf |3.197312| 0.447092148|-1.70011488|
## +-----------------+---+---+----+--------+------------+-----------+
## |angle |C | 32|Inf | Inf|-0.379489622|-3.43398720|
## | |D |118|Inf |3.646320| 1.167605160|-1.31372367|
## | |E |379|Inf |2.029941|-0.303090698|-2.08241331|
## +-----------------+---+---+----+--------+------------+-----------+
## |TC_saprolite_soil|No |445|Inf |2.261267|-0.040454955|-2.00096993|
## | |Yes| 84|Inf |2.760010| 0.191055237|-1.52605630|
## +-----------------+---+---+----+--------+------------+-----------+
## |Overall | |529|Inf |2.327797|-0.003780723|-1.91389034|
## +-----------------+---+---+----+--------+------------+-----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=1, cex.axis=1, cex.sub=1)
f2 <- lrm(risk ~ angle + building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + drainage + TC_mature_Soil + density + TC + tree +ground_veg + deforestation + banana , data=train.data, x=TRUE , y=TRUE)
stargazer(anova(f2), type="text", style="default")
eq_OLR_02 <- polr(risk ~ brick+ wood+ EN+ TC_mature_soil+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ mixed+ conc_rainfall+ wastewater+ angle+ banana+ drainage+ TC_saprolite_soil+ TC+ deforestation,
data= train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_02))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## brickTRUE -0.95863248 0.5455880 -1.75706305 3.945353e-02
## woodTRUE 0.70992717 0.3450795 2.05728556 1.982938e-02
## ENTRUE 0.48429561 0.4121252 1.17511759 1.199738e-01
## TC_mature_soilTRUE 0.62338974 0.2332306 2.67284669 3.760531e-03
## T_constructionTRUE 0.59193296 0.3732852 1.58573900 5.639926e-02
## landfillTRUE 0.08469955 0.3324418 0.25478004 3.994465e-01
## leakTRUE -0.22645913 0.2367195 -0.95665613 1.693704e-01
## garbageTRUE 0.10750341 0.3003836 0.35788704 3.602139e-01
## crackTRUE 2.09890938 0.3369541 6.22906678 2.346109e-10
## leaning_wallTRUE 1.83094078 0.5438887 3.36638854 3.807968e-04
## treeTRUE -0.28360337 0.2429547 -1.16730966 1.215427e-01
## downward_floorTRUE 1.29265791 0.3702181 3.49161144 2.400581e-04
## tiltedTRUE 1.07694567 0.3179161 3.38751521 3.526440e-04
## ground_vegTRUE 0.78618525 0.2810682 2.79713306 2.577915e-03
## scarsTRUE 3.63580275 0.3386395 10.73649936 3.429814e-27
## mixedTRUE -0.45119693 0.5076667 -0.88876600 1.870644e-01
## conc_rainfallTRUE 0.61011856 0.6204584 0.98333515 1.627213e-01
## wastewaterTRUE 0.52360366 0.2455115 2.13270512 1.647446e-02
## angleD 0.01367017 0.4768340 0.02866862 4.885644e-01
## angleE 0.70460344 0.5615076 1.25484231 1.047680e-01
## bananaTRUE 0.32181674 0.2603309 1.23618353 1.081952e-01
## drainage.L 0.97403309 0.2865389 3.39930499 3.377867e-04
## drainage.Q -0.11203751 0.1880318 -0.59584350 2.756399e-01
## TC_saprolite_soilTRUE 0.09849279 0.3025284 0.32556547 3.723766e-01
## TCTRUE -1.37418458 0.5494866 -2.50085195 6.194748e-03
## deforestationTRUE 0.33230984 0.4089782 0.81253676 2.082419e-01
## R1|R2 -1.64285793 1.1829795 -1.38874594 8.245501e-02
## R2|R3 2.71163442 1.1889701 2.28065813 1.128434e-02
## R3|R4 7.71187953 1.2574260 6.13306810 4.310011e-10
stargazer((ctable), type="text", style="default", digits=2)
##
## ======================================================
## Value Std. Error t value p value
## ------------------------------------------------------
## brickTRUE -0.96 0.55 -1.76 0.04
## woodTRUE 0.71 0.35 2.06 0.02
## ENTRUE 0.48 0.41 1.18 0.12
## TC_mature_soilTRUE 0.62 0.23 2.67 0.004
## T_constructionTRUE 0.59 0.37 1.59 0.06
## landfillTRUE 0.08 0.33 0.25 0.40
## leakTRUE -0.23 0.24 -0.96 0.17
## garbageTRUE 0.11 0.30 0.36 0.36
## crackTRUE 2.10 0.34 6.23 0
## leaning_wallTRUE 1.83 0.54 3.37 0.0004
## treeTRUE -0.28 0.24 -1.17 0.12
## downward_floorTRUE 1.29 0.37 3.49 0.0002
## tiltedTRUE 1.08 0.32 3.39 0.0004
## ground_vegTRUE 0.79 0.28 2.80 0.003
## scarsTRUE 3.64 0.34 10.74 0
## mixedTRUE -0.45 0.51 -0.89 0.19
## conc_rainfallTRUE 0.61 0.62 0.98 0.16
## wastewaterTRUE 0.52 0.25 2.13 0.02
## angleD 0.01 0.48 0.03 0.49
## angleE 0.70 0.56 1.25 0.10
## bananaTRUE 0.32 0.26 1.24 0.11
## drainage.L 0.97 0.29 3.40 0.0003
## drainage.Q -0.11 0.19 -0.60 0.28
## TC_saprolite_soilTRUE 0.10 0.30 0.33 0.37
## TCTRUE -1.37 0.55 -2.50 0.01
## deforestationTRUE 0.33 0.41 0.81 0.21
## R1| R2 -1.64 1.18 -1.39 0.08
## R2| R3 2.71 1.19 2.28 0.01
## R3| R4 7.71 1.26 6.13 0
## ------------------------------------------------------
par(mfrow=c(6,4))
plot.xmean.ordinaly (risk~ brick+ wood+ EN+ TC_mature_soil+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ mixed+ conc_rainfall+ wastewater+ angle+ banana+ drainage+ TC_saprolite_soil+ TC+ deforestation
,data=train.data, cr=TRUE , subn=FALSE , cex.lab=1.5, cex.axis=4, cex.sub=4, cex.main=4)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ EN+ TC_mature_soil+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ mixed+ conc_rainfall+ wastewater+ angle+ banana+ drainage+ TC_saprolite_soil+ TC+ deforestation,data=train.data
, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +-----------------+---+---+----+---------+------------+-----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +-----------------+---+---+----+---------+------------+-----------+
## |brick |No | 32|Inf |2.7080502| 1.272965676|-0.78845736|
## | |Yes|497|Inf |2.3070197|-0.076496033|-2.02405640|
## +-----------------+---+---+----+---------+------------+-----------+
## |wood |No |453|Inf |2.2046047|-0.190418767|-2.25495704|
## | |Yes| 76|Inf |3.6109179| 1.244324100|-0.71294981|
## +-----------------+---+---+----+---------+------------+-----------+
## |EN |No |348|Inf |1.9328381|-0.492476485|-2.39789527|
## | |Yes|181|Inf |4.0831713| 0.990981624|-1.29226541|
## +-----------------+---+---+----+---------+------------+-----------+
## |TC_mature_soil |No |251|Inf |1.9596403|-0.248279525|-2.15800386|
## | |Yes|278|Inf |2.7957558| 0.216671037|-1.72616219|
## +-----------------+---+---+----+---------+------------+-----------+
## |T_construction |No |213|Inf |1.5595661|-0.867500568|-2.81839826|
## | |Yes|316|Inf |3.4210000| 0.558372780|-1.53532994|
## +-----------------+---+---+----+---------+------------+-----------+
## |landfill |No |325|Inf |1.8281271|-0.509184934|-2.52905643|
## | |Yes|204|Inf |4.6151205| 0.828692673|-1.29098418|
## +-----------------+---+---+----+---------+------------+-----------+
## |leak |No |336|Inf |2.0014800|-0.251314428|-2.32238772|
## | |Yes|193|Inf |3.2798365| 0.431440595|-1.40583896|
## +-----------------+---+---+----+---------+------------+-----------+
## |garbage |No |347|Inf |2.0665381|-0.272568435|-2.28683674|
## | |Yes|182|Inf |3.0796138| 0.516690743|-1.40008768|
## +-----------------+---+---+----+---------+------------+-----------+
## |crack |No |444|Inf |2.1578106|-0.345745873|-2.73724936|
## | |Yes| 85|Inf |4.4308168| 2.772588722|-0.07061757|
## +-----------------+---+---+----+---------+------------+-----------+
## |leaning_wall |No |499|Inf |2.2635346|-0.108322227|-2.15131488|
## | |Yes| 30|Inf | Inf| 2.639057330| 0.13353139|
## +-----------------+---+---+----+---------+------------+-----------+
## |tree |No |214|Inf |1.7754989|-0.515813165|-2.16645292|
## | |Yes|315|Inf |2.9278549| 0.339738434|-1.76606998|
## +-----------------+---+---+----+---------+------------+-----------+
## |downward_floor |No |467|Inf |2.1901071|-0.262743124|-2.26318255|
## | |Yes| 62|Inf | Inf| 4.110873864|-0.45953233|
## +-----------------+---+---+----+---------+------------+-----------+
## |tilted |No |425|Inf |2.1088948|-0.444840273|-2.50807371|
## | |Yes|104|Inf |4.6347290| 2.793208009|-0.63598877|
## +-----------------+---+---+----+---------+------------+-----------+
## |ground_veg |No |147|Inf |1.2791962|-1.319602987|-2.73002911|
## | |Yes|382|Inf |3.1973116| 0.447092148|-1.70011488|
## +-----------------+---+---+----+---------+------------+-----------+
## |scars |No |320|Inf |1.7844867|-1.366876275|-4.36944785|
## | |Yes|209|Inf |5.3375381| 2.990719732|-0.81785066|
## +-----------------+---+---+----+---------+------------+-----------+
## |mixed |No |490|Inf |2.2914118|-0.073502462|-2.00798258|
## | |Yes| 39|Inf |2.9177707| 0.934309237|-1.06471074|
## +-----------------+---+---+----+---------+------------+-----------+
## |conc_rainfall |No | 14|Inf |0.0000000| -Inf| -Inf|
## | |Yes|515|Inf |2.4744353| 0.050496164|-1.88305089|
## +-----------------+---+---+----+---------+------------+-----------+
## |wastewater |No |206|Inf |1.6933194|-0.433864583|-2.78295151|
## | |Yes|323|Inf |3.0220496| 0.267843730|-1.56189697|
## +-----------------+---+---+----+---------+------------+-----------+
## |angle |C | 32|Inf | Inf|-0.379489622|-3.43398720|
## | |D |118|Inf |3.6463198| 1.167605160|-1.31372367|
## | |E |379|Inf |2.0299409|-0.303090698|-2.08241331|
## +-----------------+---+---+----+---------+------------+-----------+
## |banana |No |360|Inf |1.9977017|-0.279584862|-2.19722458|
## | |Yes|169|Inf |3.7196511| 0.597003320|-1.45424502|
## +-----------------+---+---+----+---------+------------+-----------+
## |drainage |Y | 62|Inf |0.7419373|-2.061423036| -Inf|
## | |P |237|Inf |2.3841651|-0.508575904|-2.69462718|
## | |N |230|Inf |3.4612616| 0.996829594|-1.20585782|
## +-----------------+---+---+----+---------+------------+-----------+
## |TC_saprolite_soil|No |445|Inf |2.2612669|-0.040454955|-2.00096993|
## | |Yes| 84|Inf |2.7600099| 0.191055237|-1.52605630|
## +-----------------+---+---+----+---------+------------+-----------+
## |TC |No | 26|Inf | Inf| 1.203972804|-1.20397280|
## | |Yes|503|Inf |2.2723452|-0.059659836|-1.96191049|
## +-----------------+---+---+----+---------+------------+-----------+
## |deforestation |No |491|Inf |2.3435931| 0.052965536|-1.89790093|
## | |Yes| 38|Inf |2.1400662|-0.773189888|-2.14006616|
## +-----------------+---+---+----+---------+------------+-----------+
## |Overall | |529|Inf |2.3277965|-0.003780723|-1.91389034|
## +-----------------+---+---+----+---------+------------+-----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=1, cex.axis=2, cex.sub=1)
f3 <- lrm(risk ~ angle +building + EN + DepTaludeAterro+ DepTaludeCorte+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall_water+ wastewater+ tree + TC , data=train.data, x=TRUE , y=TRUE) stargazer(anova(f3), type=“text”, style=“default”)
# x=TRUE, y=TRUE used by resid() below
eq_OLR_03 <- polr(risk ~ wood+ TC_mature_soil+ T_construction+ landfill+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage, data=train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_03))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## woodTRUE 0.84125762 0.3235614 2.59999340 4.661278e-03
## TC_mature_soilTRUE 0.45997878 0.2181854 2.10820115 1.750680e-02
## T_constructionTRUE 0.70164945 0.2931393 2.39357028 8.342642e-03
## landfillTRUE -0.08782343 0.2926312 -0.30011645 3.820442e-01
## crackTRUE 2.04329525 0.3275123 6.23883565 2.204199e-10
## leaning_wallTRUE 1.88862216 0.5354252 3.52733172 2.098852e-04
## treeTRUE -0.29800037 0.2320711 -1.28409057 9.955513e-02
## downward_floorTRUE 1.19189772 0.3528581 3.37783824 3.652902e-04
## tiltedTRUE 1.07269191 0.3099721 3.46060791 2.694786e-04
## ground_vegTRUE 0.81136372 0.2696212 3.00927263 1.309370e-03
## scarsTRUE 3.56885323 0.3322471 10.74156300 3.246780e-27
## conc_rainfallTRUE 0.71733097 0.6108912 1.17423684 1.201501e-01
## wastewaterTRUE 0.46337270 0.2340014 1.98021378 2.383976e-02
## bananaTRUE 0.24154605 0.2467598 0.97887096 1.638219e-01
## drainage.L 0.96556502 0.2784342 3.46783913 2.623306e-04
## drainage.Q -0.11231798 0.1852456 -0.60631928 2.721514e-01
## R1|R2 -0.01420245 0.5935702 -0.02392716 4.904554e-01
## R2|R3 4.23561369 0.6473844 6.54265659 3.021775e-11
## R3|R4 9.12524842 0.7623660 11.96964284 2.562438e-33
stargazer((ctable), type="text", style="default", digits = 2)
##
## ===================================================
## Value Std. Error t value p value
## ---------------------------------------------------
## woodTRUE 0.84 0.32 2.60 0.005
## TC_mature_soilTRUE 0.46 0.22 2.11 0.02
## T_constructionTRUE 0.70 0.29 2.39 0.01
## landfillTRUE -0.09 0.29 -0.30 0.38
## crackTRUE 2.04 0.33 6.24 0
## leaning_wallTRUE 1.89 0.54 3.53 0.0002
## treeTRUE -0.30 0.23 -1.28 0.10
## downward_floorTRUE 1.19 0.35 3.38 0.0004
## tiltedTRUE 1.07 0.31 3.46 0.0003
## ground_vegTRUE 0.81 0.27 3.01 0.001
## scarsTRUE 3.57 0.33 10.74 0
## conc_rainfallTRUE 0.72 0.61 1.17 0.12
## wastewaterTRUE 0.46 0.23 1.98 0.02
## bananaTRUE 0.24 0.25 0.98 0.16
## drainage.L 0.97 0.28 3.47 0.0003
## drainage.Q -0.11 0.19 -0.61 0.27
## R1| R2 -0.01 0.59 -0.02 0.49
## R2| R3 4.24 0.65 6.54 0
## R3| R4 9.13 0.76 11.97 0
## ---------------------------------------------------
#print (f3 , latex =TRUE , coefs =5)
par(mfrow=c(3,5))
plot.xmean.ordinaly (risk ~ wood+ TC_mature_soil+ T_construction+ landfill+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage,,
data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~wood+ TC_mature_soil+ T_construction+ landfill+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +--------------+---+---+----+---------+------------+-----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +--------------+---+---+----+---------+------------+-----------+
## |wood |No |453|Inf |2.2046047|-0.190418767|-2.25495704|
## | |Yes| 76|Inf |3.6109179| 1.244324100|-0.71294981|
## +--------------+---+---+----+---------+------------+-----------+
## |TC_mature_soil|No |251|Inf |1.9596403|-0.248279525|-2.15800386|
## | |Yes|278|Inf |2.7957558| 0.216671037|-1.72616219|
## +--------------+---+---+----+---------+------------+-----------+
## |T_construction|No |213|Inf |1.5595661|-0.867500568|-2.81839826|
## | |Yes|316|Inf |3.4210000| 0.558372780|-1.53532994|
## +--------------+---+---+----+---------+------------+-----------+
## |landfill |No |325|Inf |1.8281271|-0.509184934|-2.52905643|
## | |Yes|204|Inf |4.6151205| 0.828692673|-1.29098418|
## +--------------+---+---+----+---------+------------+-----------+
## |crack |No |444|Inf |2.1578106|-0.345745873|-2.73724936|
## | |Yes| 85|Inf |4.4308168| 2.772588722|-0.07061757|
## +--------------+---+---+----+---------+------------+-----------+
## |leaning_wall |No |499|Inf |2.2635346|-0.108322227|-2.15131488|
## | |Yes| 30|Inf | Inf| 2.639057330| 0.13353139|
## +--------------+---+---+----+---------+------------+-----------+
## |tree |No |214|Inf |1.7754989|-0.515813165|-2.16645292|
## | |Yes|315|Inf |2.9278549| 0.339738434|-1.76606998|
## +--------------+---+---+----+---------+------------+-----------+
## |downward_floor|No |467|Inf |2.1901071|-0.262743124|-2.26318255|
## | |Yes| 62|Inf | Inf| 4.110873864|-0.45953233|
## +--------------+---+---+----+---------+------------+-----------+
## |tilted |No |425|Inf |2.1088948|-0.444840273|-2.50807371|
## | |Yes|104|Inf |4.6347290| 2.793208009|-0.63598877|
## +--------------+---+---+----+---------+------------+-----------+
## |ground_veg |No |147|Inf |1.2791962|-1.319602987|-2.73002911|
## | |Yes|382|Inf |3.1973116| 0.447092148|-1.70011488|
## +--------------+---+---+----+---------+------------+-----------+
## |scars |No |320|Inf |1.7844867|-1.366876275|-4.36944785|
## | |Yes|209|Inf |5.3375381| 2.990719732|-0.81785066|
## +--------------+---+---+----+---------+------------+-----------+
## |conc_rainfall |No | 14|Inf |0.0000000| -Inf| -Inf|
## | |Yes|515|Inf |2.4744353| 0.050496164|-1.88305089|
## +--------------+---+---+----+---------+------------+-----------+
## |wastewater |No |206|Inf |1.6933194|-0.433864583|-2.78295151|
## | |Yes|323|Inf |3.0220496| 0.267843730|-1.56189697|
## +--------------+---+---+----+---------+------------+-----------+
## |banana |No |360|Inf |1.9977017|-0.279584862|-2.19722458|
## | |Yes|169|Inf |3.7196511| 0.597003320|-1.45424502|
## +--------------+---+---+----+---------+------------+-----------+
## |drainage |Y | 62|Inf |0.7419373|-2.061423036| -Inf|
## | |P |237|Inf |2.3841651|-0.508575904|-2.69462718|
## | |N |230|Inf |3.4612616| 0.996829594|-1.20585782|
## +--------------+---+---+----+---------+------------+-----------+
## |Overall | |529|Inf |2.3277965|-0.003780723|-1.91389034|
## +--------------+---+---+----+---------+------------+-----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.6, cex.axis=0.6, cex.sub=0.6)
f4 <- lrm(risk ~ building + EN
+ DepEncNatural
+ crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + drainage + TC_mature_Soil + TC + +ground_veg
,data=train.data, x=TRUE , y=TRUE) # x=TRUE, y=TRUE used by resid() below #print (f4 , latex =TRUE , coefs =5) stargazer(anova(f4), type=“text”, style=“default”)
eq_OLR_04 <- polr(risk~ wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage
, data= train.data
, method = "logistic", Hess = TRUE)
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- coef(summary(eq_OLR_04))
ctable <- cbind(ctable, "p value" = p )
## Warning in cbind(ctable, `p value` = p): number of rows of result is not a
## multiple of vector length (arg 2)
ctable
## Value Std. Error t value p value
## woodTRUE 0.83582453 0.3231536 2.58646200 4.661278e-03
## TC_mature_soilTRUE 0.46928079 0.2159863 2.17273418 1.750680e-02
## T_constructionTRUE 0.64785978 0.2319182 2.79348381 8.342642e-03
## crackTRUE 2.03595987 0.3264925 6.23585457 3.820442e-01
## leaning_wallTRUE 1.88873561 0.5349995 3.53035028 2.204199e-10
## treeTRUE -0.29669085 0.2320897 -1.27834547 2.098852e-04
## downward_floorTRUE 1.18185782 0.3512132 3.36507224 9.955513e-02
## tiltedTRUE 1.05561736 0.3045309 3.46637205 3.652902e-04
## ground_vegTRUE 0.80607603 0.2691129 2.99530772 2.694786e-04
## scarsTRUE 3.56915888 0.3321841 10.74452208 1.309370e-03
## conc_rainfallTRUE 0.70799658 0.6099675 1.16071204 3.246780e-27
## wastewaterTRUE 0.47604367 0.2301064 2.06879773 1.201501e-01
## bananaTRUE 0.24232550 0.2467204 0.98218659 2.383976e-02
## drainage.L 0.96265184 0.2782075 3.46019415 1.638219e-01
## drainage.Q -0.11456294 0.1850794 -0.61899358 2.623306e-04
## R1|R2 -0.01715554 0.5933297 -0.02891402 2.721514e-01
## R2|R3 4.23008197 0.6468705 6.53930270 4.904554e-01
## R3|R4 9.12275834 0.7621375 11.96996394 3.021775e-11
stargazer((ctable), type="text", style="default", digits=2)
##
## ===================================================
## Value Std. Error t value p value
## ---------------------------------------------------
## woodTRUE 0.84 0.32 2.59 0.005
## TC_mature_soilTRUE 0.47 0.22 2.17 0.02
## T_constructionTRUE 0.65 0.23 2.79 0.01
## crackTRUE 2.04 0.33 6.24 0.38
## leaning_wallTRUE 1.89 0.53 3.53 0
## treeTRUE -0.30 0.23 -1.28 0.0002
## downward_floorTRUE 1.18 0.35 3.37 0.10
## tiltedTRUE 1.06 0.30 3.47 0.0004
## ground_vegTRUE 0.81 0.27 3.00 0.0003
## scarsTRUE 3.57 0.33 10.74 0.001
## conc_rainfallTRUE 0.71 0.61 1.16 0
## wastewaterTRUE 0.48 0.23 2.07 0.12
## bananaTRUE 0.24 0.25 0.98 0.02
## drainage.L 0.96 0.28 3.46 0.16
## drainage.Q -0.11 0.19 -0.62 0.0003
## R1| R2 -0.02 0.59 -0.03 0.27
## R2| R3 4.23 0.65 6.54 0.49
## R3| R4 9.12 0.76 11.97 0
## ---------------------------------------------------
par(mfrow=c(4,4))
plot.xmean.ordinaly (risk ~ wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage
,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage
, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +--------------+---+---+----+---------+------------+-----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +--------------+---+---+----+---------+------------+-----------+
## |wood |No |453|Inf |2.2046047|-0.190418767|-2.25495704|
## | |Yes| 76|Inf |3.6109179| 1.244324100|-0.71294981|
## +--------------+---+---+----+---------+------------+-----------+
## |TC_mature_soil|No |251|Inf |1.9596403|-0.248279525|-2.15800386|
## | |Yes|278|Inf |2.7957558| 0.216671037|-1.72616219|
## +--------------+---+---+----+---------+------------+-----------+
## |T_construction|No |213|Inf |1.5595661|-0.867500568|-2.81839826|
## | |Yes|316|Inf |3.4210000| 0.558372780|-1.53532994|
## +--------------+---+---+----+---------+------------+-----------+
## |crack |No |444|Inf |2.1578106|-0.345745873|-2.73724936|
## | |Yes| 85|Inf |4.4308168| 2.772588722|-0.07061757|
## +--------------+---+---+----+---------+------------+-----------+
## |leaning_wall |No |499|Inf |2.2635346|-0.108322227|-2.15131488|
## | |Yes| 30|Inf | Inf| 2.639057330| 0.13353139|
## +--------------+---+---+----+---------+------------+-----------+
## |tree |No |214|Inf |1.7754989|-0.515813165|-2.16645292|
## | |Yes|315|Inf |2.9278549| 0.339738434|-1.76606998|
## +--------------+---+---+----+---------+------------+-----------+
## |downward_floor|No |467|Inf |2.1901071|-0.262743124|-2.26318255|
## | |Yes| 62|Inf | Inf| 4.110873864|-0.45953233|
## +--------------+---+---+----+---------+------------+-----------+
## |tilted |No |425|Inf |2.1088948|-0.444840273|-2.50807371|
## | |Yes|104|Inf |4.6347290| 2.793208009|-0.63598877|
## +--------------+---+---+----+---------+------------+-----------+
## |ground_veg |No |147|Inf |1.2791962|-1.319602987|-2.73002911|
## | |Yes|382|Inf |3.1973116| 0.447092148|-1.70011488|
## +--------------+---+---+----+---------+------------+-----------+
## |scars |No |320|Inf |1.7844867|-1.366876275|-4.36944785|
## | |Yes|209|Inf |5.3375381| 2.990719732|-0.81785066|
## +--------------+---+---+----+---------+------------+-----------+
## |conc_rainfall |No | 14|Inf |0.0000000| -Inf| -Inf|
## | |Yes|515|Inf |2.4744353| 0.050496164|-1.88305089|
## +--------------+---+---+----+---------+------------+-----------+
## |wastewater |No |206|Inf |1.6933194|-0.433864583|-2.78295151|
## | |Yes|323|Inf |3.0220496| 0.267843730|-1.56189697|
## +--------------+---+---+----+---------+------------+-----------+
## |banana |No |360|Inf |1.9977017|-0.279584862|-2.19722458|
## | |Yes|169|Inf |3.7196511| 0.597003320|-1.45424502|
## +--------------+---+---+----+---------+------------+-----------+
## |drainage |Y | 62|Inf |0.7419373|-2.061423036| -Inf|
## | |P |237|Inf |2.3841651|-0.508575904|-2.69462718|
## | |N |230|Inf |3.4612616| 0.996829594|-1.20585782|
## +--------------+---+---+----+---------+------------+-----------+
## |Overall | |529|Inf |2.3277965|-0.003780723|-1.91389034|
## +--------------+---+---+----+---------+------------+-----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)
# x=TRUE, y=TRUE used by resid() below
#print (f1 , latex =TRUE , coefs =5)
#stargazer(anova(f1), type="text", style="default")
eq_OLR_05 <- polr(risk ~ brick+ wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall+ wastewater+ ground_veg, data= train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_05))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## brickTRUE -0.68448293 0.4422895 -1.54759018 6.086050e-02
## woodTRUE 0.93495221 0.3213409 2.90953371 1.809842e-03
## TC_mature_soilTRUE 0.48843387 0.2128941 2.29425794 1.088784e-02
## T_constructionTRUE 0.62176979 0.2268605 2.74075858 3.064876e-03
## crackTRUE 2.03573573 0.3236759 6.28942692 1.593200e-10
## leaning_wallTRUE 1.80313709 0.5248861 3.43529192 2.959579e-04
## scarsTRUE 3.65259960 0.3299800 11.06915386 8.853226e-29
## downward_floorTRUE 1.28531252 0.3522235 3.64913884 1.315604e-04
## tiltedTRUE 1.15534958 0.3048233 3.79022705 7.525482e-05
## conc_rainfallTRUE 1.11130377 0.5776637 1.92379022 2.719044e-02
## wastewaterTRUE 0.64328397 0.2221182 2.89613373 1.888957e-03
## ground_vegTRUE 0.89686946 0.2410767 3.72026633 9.950640e-05
## R1|R2 -0.05287725 0.7128386 -0.07417844 4.704342e-01
## R2|R3 4.03681794 0.7653634 5.27438047 6.660265e-08
## R3|R4 8.94611755 0.8555459 10.45661940 6.832213e-26
stargazer((ctable), type="text", style="default", digits = 2)
##
## ===================================================
## Value Std. Error t value p value
## ---------------------------------------------------
## brickTRUE -0.68 0.44 -1.55 0.06
## woodTRUE 0.93 0.32 2.91 0.002
## TC_mature_soilTRUE 0.49 0.21 2.29 0.01
## T_constructionTRUE 0.62 0.23 2.74 0.003
## crackTRUE 2.04 0.32 6.29 0
## leaning_wallTRUE 1.80 0.52 3.44 0.0003
## scarsTRUE 3.65 0.33 11.07 0
## downward_floorTRUE 1.29 0.35 3.65 0.0001
## tiltedTRUE 1.16 0.30 3.79 0.0001
## conc_rainfallTRUE 1.11 0.58 1.92 0.03
## wastewaterTRUE 0.64 0.22 2.90 0.002
## ground_vegTRUE 0.90 0.24 3.72 0.0001
## R1| R2 -0.05 0.71 -0.07 0.47
## R2| R3 4.04 0.77 5.27 0.0000
## R3| R4 8.95 0.86 10.46 0
## ---------------------------------------------------
par(mfrow=c(3,4))
plot.xmean.ordinaly (risk ~ brick+ wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall+ wastewater+ ground_veg
,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall+ wastewater+ ground_veg
, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +--------------+---+---+----+--------+------------+-----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +--------------+---+---+----+--------+------------+-----------+
## |brick |No | 32|Inf |2.708050| 1.272965676|-0.78845736|
## | |Yes|497|Inf |2.307020|-0.076496033|-2.02405640|
## +--------------+---+---+----+--------+------------+-----------+
## |wood |No |453|Inf |2.204605|-0.190418767|-2.25495704|
## | |Yes| 76|Inf |3.610918| 1.244324100|-0.71294981|
## +--------------+---+---+----+--------+------------+-----------+
## |TC_mature_soil|No |251|Inf |1.959640|-0.248279525|-2.15800386|
## | |Yes|278|Inf |2.795756| 0.216671037|-1.72616219|
## +--------------+---+---+----+--------+------------+-----------+
## |T_construction|No |213|Inf |1.559566|-0.867500568|-2.81839826|
## | |Yes|316|Inf |3.421000| 0.558372780|-1.53532994|
## +--------------+---+---+----+--------+------------+-----------+
## |crack |No |444|Inf |2.157811|-0.345745873|-2.73724936|
## | |Yes| 85|Inf |4.430817| 2.772588722|-0.07061757|
## +--------------+---+---+----+--------+------------+-----------+
## |leaning_wall |No |499|Inf |2.263535|-0.108322227|-2.15131488|
## | |Yes| 30|Inf | Inf| 2.639057330| 0.13353139|
## +--------------+---+---+----+--------+------------+-----------+
## |scars |No |320|Inf |1.784487|-1.366876275|-4.36944785|
## | |Yes|209|Inf |5.337538| 2.990719732|-0.81785066|
## +--------------+---+---+----+--------+------------+-----------+
## |downward_floor|No |467|Inf |2.190107|-0.262743124|-2.26318255|
## | |Yes| 62|Inf | Inf| 4.110873864|-0.45953233|
## +--------------+---+---+----+--------+------------+-----------+
## |tilted |No |425|Inf |2.108895|-0.444840273|-2.50807371|
## | |Yes|104|Inf |4.634729| 2.793208009|-0.63598877|
## +--------------+---+---+----+--------+------------+-----------+
## |conc_rainfall |No | 14|Inf |0.000000| -Inf| -Inf|
## | |Yes|515|Inf |2.474435| 0.050496164|-1.88305089|
## +--------------+---+---+----+--------+------------+-----------+
## |wastewater |No |206|Inf |1.693319|-0.433864583|-2.78295151|
## | |Yes|323|Inf |3.022050| 0.267843730|-1.56189697|
## +--------------+---+---+----+--------+------------+-----------+
## |ground_veg |No |147|Inf |1.279196|-1.319602987|-2.73002911|
## | |Yes|382|Inf |3.197312| 0.447092148|-1.70011488|
## +--------------+---+---+----+--------+------------+-----------+
## |Overall | |529|Inf |2.327797|-0.003780723|-1.91389034|
## +--------------+---+---+----+--------+------------+-----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)
# x=TRUE, y=TRUE used by resid() below
#print (f1 , latex =TRUE , coefs =5)
#stargazer(anova(f1), type="text", style="default")
eq_OLR_06 <- polr(risk ~ brick+ wood+ mixed+ EN+ TC+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ tilted+ angle+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana, data= train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_06))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## brickTRUE -0.93931481 0.5397329 -1.74033282 4.090030e-02
## woodTRUE 0.66136414 0.3259215 2.02921291 2.121830e-02
## mixedTRUE -0.03099172 0.4900748 -0.06323875 4.747882e-01
## ENTRUE 0.52965497 0.4008171 1.32143806 9.317767e-02
## TCTRUE -1.00812087 0.5132688 -1.96411881 2.475816e-02
## T_constructionTRUE 0.50301570 0.3577433 1.40608018 7.985016e-02
## landfillTRUE 0.12753941 0.3220020 0.39608266 3.460220e-01
## leakTRUE 0.01331656 0.2261086 0.05889456 4.765180e-01
## garbageTRUE 0.18355883 0.2897499 0.63350774 2.632011e-01
## crackTRUE 2.10415748 0.3286008 6.40338537 7.598448e-11
## leaning_wallTRUE 1.84423156 0.5374334 3.43155354 3.000673e-04
## treeTRUE -0.24615528 0.2348731 -1.04803510 1.473112e-01
## tiltedTRUE 1.20683744 0.3120180 3.86784548 5.490060e-05
## angleD 0.23882256 0.4645472 0.51409749 3.035919e-01
## angleE 0.78920419 0.5435980 1.45181586 7.327641e-02
## ground_vegTRUE 0.91594576 0.2670198 3.43025458 3.015076e-04
## scarsTRUE 3.74718317 0.3338173 11.22525095 1.532575e-29
## conc_rainfallTRUE 1.44252931 0.5807357 2.48396892 6.496357e-03
## wastewaterTRUE 0.56442413 0.2286149 2.46888647 6.776711e-03
## bananaTRUE 0.32338244 0.2510756 1.28798832 9.887502e-02
## R1|R2 -0.48612219 1.1240503 -0.43247370 3.326986e-01
## R2|R3 3.53865419 1.1462990 3.08702534 1.010852e-03
## R3|R4 8.37823450 1.2133569 6.90500441 2.510093e-12
stargazer((ctable), type="text", style="default", digits = 2)
##
## ===================================================
## Value Std. Error t value p value
## ---------------------------------------------------
## brickTRUE -0.94 0.54 -1.74 0.04
## woodTRUE 0.66 0.33 2.03 0.02
## mixedTRUE -0.03 0.49 -0.06 0.47
## ENTRUE 0.53 0.40 1.32 0.09
## TCTRUE -1.01 0.51 -1.96 0.02
## T_constructionTRUE 0.50 0.36 1.41 0.08
## landfillTRUE 0.13 0.32 0.40 0.35
## leakTRUE 0.01 0.23 0.06 0.48
## garbageTRUE 0.18 0.29 0.63 0.26
## crackTRUE 2.10 0.33 6.40 0
## leaning_wallTRUE 1.84 0.54 3.43 0.0003
## treeTRUE -0.25 0.23 -1.05 0.15
## tiltedTRUE 1.21 0.31 3.87 0.0001
## angleD 0.24 0.46 0.51 0.30
## angleE 0.79 0.54 1.45 0.07
## ground_vegTRUE 0.92 0.27 3.43 0.0003
## scarsTRUE 3.75 0.33 11.23 0
## conc_rainfallTRUE 1.44 0.58 2.48 0.01
## wastewaterTRUE 0.56 0.23 2.47 0.01
## bananaTRUE 0.32 0.25 1.29 0.10
## R1| R2 -0.49 1.12 -0.43 0.33
## R2| R3 3.54 1.15 3.09 0.001
## R3| R4 8.38 1.21 6.91 0
## ---------------------------------------------------
par(mfrow=c(5,4))
plot.xmean.ordinaly (risk ~ brick+ wood+ mixed+ EN+ TC+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ tilted+ angle+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana
,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ mixed+ EN+ TC+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ tilted+ angle+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana
, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +--------------+---+---+----+--------+------------+-----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +--------------+---+---+----+--------+------------+-----------+
## |brick |No | 32|Inf |2.708050| 1.272965676|-0.78845736|
## | |Yes|497|Inf |2.307020|-0.076496033|-2.02405640|
## +--------------+---+---+----+--------+------------+-----------+
## |wood |No |453|Inf |2.204605|-0.190418767|-2.25495704|
## | |Yes| 76|Inf |3.610918| 1.244324100|-0.71294981|
## +--------------+---+---+----+--------+------------+-----------+
## |mixed |No |490|Inf |2.291412|-0.073502462|-2.00798258|
## | |Yes| 39|Inf |2.917771| 0.934309237|-1.06471074|
## +--------------+---+---+----+--------+------------+-----------+
## |EN |No |348|Inf |1.932838|-0.492476485|-2.39789527|
## | |Yes|181|Inf |4.083171| 0.990981624|-1.29226541|
## +--------------+---+---+----+--------+------------+-----------+
## |TC |No | 26|Inf | Inf| 1.203972804|-1.20397280|
## | |Yes|503|Inf |2.272345|-0.059659836|-1.96191049|
## +--------------+---+---+----+--------+------------+-----------+
## |T_construction|No |213|Inf |1.559566|-0.867500568|-2.81839826|
## | |Yes|316|Inf |3.421000| 0.558372780|-1.53532994|
## +--------------+---+---+----+--------+------------+-----------+
## |landfill |No |325|Inf |1.828127|-0.509184934|-2.52905643|
## | |Yes|204|Inf |4.615121| 0.828692673|-1.29098418|
## +--------------+---+---+----+--------+------------+-----------+
## |leak |No |336|Inf |2.001480|-0.251314428|-2.32238772|
## | |Yes|193|Inf |3.279837| 0.431440595|-1.40583896|
## +--------------+---+---+----+--------+------------+-----------+
## |garbage |No |347|Inf |2.066538|-0.272568435|-2.28683674|
## | |Yes|182|Inf |3.079614| 0.516690743|-1.40008768|
## +--------------+---+---+----+--------+------------+-----------+
## |crack |No |444|Inf |2.157811|-0.345745873|-2.73724936|
## | |Yes| 85|Inf |4.430817| 2.772588722|-0.07061757|
## +--------------+---+---+----+--------+------------+-----------+
## |leaning_wall |No |499|Inf |2.263535|-0.108322227|-2.15131488|
## | |Yes| 30|Inf | Inf| 2.639057330| 0.13353139|
## +--------------+---+---+----+--------+------------+-----------+
## |tree |No |214|Inf |1.775499|-0.515813165|-2.16645292|
## | |Yes|315|Inf |2.927855| 0.339738434|-1.76606998|
## +--------------+---+---+----+--------+------------+-----------+
## |tilted |No |425|Inf |2.108895|-0.444840273|-2.50807371|
## | |Yes|104|Inf |4.634729| 2.793208009|-0.63598877|
## +--------------+---+---+----+--------+------------+-----------+
## |angle |C | 32|Inf | Inf|-0.379489622|-3.43398720|
## | |D |118|Inf |3.646320| 1.167605160|-1.31372367|
## | |E |379|Inf |2.029941|-0.303090698|-2.08241331|
## +--------------+---+---+----+--------+------------+-----------+
## |ground_veg |No |147|Inf |1.279196|-1.319602987|-2.73002911|
## | |Yes|382|Inf |3.197312| 0.447092148|-1.70011488|
## +--------------+---+---+----+--------+------------+-----------+
## |scars |No |320|Inf |1.784487|-1.366876275|-4.36944785|
## | |Yes|209|Inf |5.337538| 2.990719732|-0.81785066|
## +--------------+---+---+----+--------+------------+-----------+
## |conc_rainfall |No | 14|Inf |0.000000| -Inf| -Inf|
## | |Yes|515|Inf |2.474435| 0.050496164|-1.88305089|
## +--------------+---+---+----+--------+------------+-----------+
## |wastewater |No |206|Inf |1.693319|-0.433864583|-2.78295151|
## | |Yes|323|Inf |3.022050| 0.267843730|-1.56189697|
## +--------------+---+---+----+--------+------------+-----------+
## |banana |No |360|Inf |1.997702|-0.279584862|-2.19722458|
## | |Yes|169|Inf |3.719651| 0.597003320|-1.45424502|
## +--------------+---+---+----+--------+------------+-----------+
## |Overall | |529|Inf |2.327797|-0.003780723|-1.91389034|
## +--------------+---+---+----+--------+------------+-----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)
predictedLevel1 <- predict(eq_OLR_01, test.data) # predict the levels directly
predictedScores1 <- predict(eq_OLR_01, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel1)
## predictedLevel1
## R1 R2 R3 R4
## R1 5 14 0 0
## R2 1 88 4 0
## R3 0 20 54 10
## R4 0 0 16 12
p1 <- mean(as.character(test.data$risk) != as.character(predictedLevel1)) #misclassification error
p1
## [1] 0.2901786
predictedLevel2 <- predict(eq_OLR_02, test.data) # predict the levels directly
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel2)
## predictedLevel2
## R1 R2 R3 R4
## R1 6 13 0 0
## R2 3 83 7 0
## R3 0 20 55 9
## R4 0 0 16 12
p2 <- mean(as.character(test.data$risk) != as.character(predictedLevel2))
p2
## [1] 0.3035714
predictedLevel3 <- predict(eq_OLR_03, test.data) # predict the levels directly
predictedScores1 <- predict(eq_OLR_03, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel3)
## predictedLevel3
## R1 R2 R3 R4
## R1 5 14 0 0
## R2 3 86 4 0
## R3 0 20 55 9
## R4 0 0 16 12
p3 <- mean(as.character(test.data$risk) != as.character(predictedLevel3))
p3
## [1] 0.2946429
predictedLevel4 <- predict(eq_OLR_04, test.data) # predict the levels directly
predictedScores1 <- predict(eq_OLR_04, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel4)
## predictedLevel4
## R1 R2 R3 R4
## R1 5 14 0 0
## R2 3 86 4 0
## R3 0 20 55 9
## R4 0 0 16 12
p4 <- mean(as.character(test.data$risk) != as.character(predictedLevel4))
p4
## [1] 0.2946429
predictedLevel5 <- predict(eq_OLR_05, test.data) # predict the levels directly
predictedScores5 <- predict(eq_OLR_05, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel5)
## predictedLevel5
## R1 R2 R3 R4
## R1 4 15 0 0
## R2 1 88 4 0
## R3 0 20 55 9
## R4 0 0 16 12
p5 <- mean(as.character(test.data$risk) != as.character(predictedLevel5))
p5
## [1] 0.2901786
predictedLevel6 <- predict(eq_OLR_06, test.data) # predict the levels directly
predictedScores6 <- predict(eq_OLR_06, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel6)
## predictedLevel6
## R1 R2 R3 R4
## R1 6 13 0 0
## R2 2 86 5 0
## R3 0 21 53 10
## R4 0 1 13 14
p6 <- mean(as.character(test.data$risk) != as.character(predictedLevel6))
p6
## [1] 0.2901786
#Table
df2 <- data.frame(
"Equations"=c(1:6),
"Predicted"=c(1-p1,
1-p2,
1-p3,
1-p4,
1-p5,
1-p6
)
)
df2
## Equations Predicted
## 1 1 0.7098214
## 2 2 0.6964286
## 3 3 0.7053571
## 4 4 0.7053571
## 5 5 0.7098214
## 6 6 0.7098214